import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/viewmodel/new_yyt_view_model.dart';
import 'package:ls_work/viewmodel/send_order/send_order_list_view_model.dart';

import '../service_order/service_order_detail_page.dart';

class SendOrderListPage extends BaseStatefulMvvmWidget {
  @override
  State<StatefulWidget> createState() => _SendOrderListState();
}

class _SendOrderListState
    extends BaseMvvmListState<SendOrderListViewModel, SendOrderListPage> {
  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      backgroundColor: Colours.bg_color,
      appBar: AppBar(
        title: Text('服务派单'),
      ),
      body: loadingContentWidget,
    );
  }

  @override
  Widget createItemWidget(int index) {
    var item = viewModel.listItems[index];
    return Stack(
      children: [
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              children: [
                CommonText('工单编号：${item.orderServeCode}',
                    textSize: 14, textColor: Color(0xff848689))
                    .setWeight(1),
                CommonText('${!item.rationStatusName.isNullOrEmpty()?item.rationStatusName:item.statusName}',
                    textSize: 15,textColor: Colours.app_main)
              ],
            ),
            Container(
              height: 5,
            ),
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Icon(
                  Icons.house_rounded,
                  color: Colors.white,
                )
                    .addToContainer(
                    decoration: BoxDecoration(
                        color: Color(0xff3EB9AC),
                        borderRadius: 8.borderRadius),
                    width: 40,
                    height: 40)
                    .addToContainer(margin: EdgeInsets.only(top: 4, right: 12)),
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      height: 8,
                    ),
                    CommonText('${item.orderServeItemName}',
                        textSize: 18, fontWeight: FontWeight.w600),
                    Container(
                      height: 8,
                    ),
                    CommonText('预约时间：${item.markDuration ?? ""}',
                        textSize: 14, textColor: Color(0xff848689)),
                    Container(
                      height: 5,
                    ),
                    CommonText('服务对象：${item.orderServeHuman ?? ""}',
                        textSize: 14, textColor: Color(0xff848689)),
                    Container(
                      height: 5,
                    ),
                    CommonText('服务地址：${item.orderServeAddress ?? ""}',
                        textSize: 14, textColor: Color(0xff848689)),
                    Container(
                      height: 5,
                    ),
                    CommonText('联系电话：${item.humanMobile ?? ""}',
                        textSize: 14, textColor: Color(0xff848689)),
                  ],
                ).setWeight(1)
              ],
            ),
            
            if(NewYytViewModel.canSendOrder) Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                UnconstrainedBox(
                  child: ElevatedButton(onPressed: (){
                    Go().push(ServiceOrderDetailPage(
                      showDetail: false,
                      orderId: item.id!,
                    ));
                  }, child: Text('派单'),style: ButtonStyle(
                      shape: WidgetStateProperty.all(StadiumBorder()),
                      minimumSize: WidgetStateProperty.all(Size(40, 30)),
                    elevation: WidgetStateProperty.all(0.0)
                  ),),
                )
              ],
            )
          ],
        ),
      ],
    ).onTap(() {
      Go().push(ServiceOrderDetailPage(
        showDetail: true,
        orderId: item.id!,
      ));
    }).addToContainer(
        decoration:
        BoxDecoration(color: Colors.white, borderRadius: 8.borderRadius),
        margin: EdgeInsets.symmetric(
          horizontal: 16,
        ),
        padding: EdgeInsets.all(10));
  }

  @override
  SendOrderListViewModel createViewModel() {
    return SendOrderListViewModel(context, '10231');
  }

  @override
  Widget get separatorDivider => Container(height: 10,);

  @override
  EdgeInsets get listPadding => EdgeInsets.symmetric(vertical: 15);

  @override
  bool get canPullUp => true;
}
